-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support autocorrection even if reject
is used on Performance/Count
#307
Conversation
array.count { | ||
!(foo | ||
bar) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it needs to be autocorrected to the following for compatible.
array.count { | |
!(foo | |
bar) | |
} | |
array.count { | |
foo | |
!bar | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is the point I mentioned at the end of the description, do you have any better ideas to achieve that, and what about this thought?
other cops autocorrects it to some other good form
By the way, you say "for compatible", what exactly is incompatible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah..., it doesn't contribute to compatibility. But !
to foo
makes no sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the implementation that Solargraph uses to estimate the method's return type might be helpful:
If we have a similar implementation, we can see which nodes can be the return value of a block, and if we negate them, I think we can achieve most of what we want to do. Though this may be a little too heavy implementation for this cop to handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can be achieved by inverting the last sentence of block with !
. Anyway, let's make a better autocorrect separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it so that the only last statement is negated in the case of begin
node as a simple enough approach. I think indeed it's going to work there, even if it's not a perfect autocorrection.
65e43ed
to
3554550
Compare
Thanks! |
Until now, autocorrect was given up when reject was used, but it is now supported.
The last one looks a bit weird but I think other cops autocorrects it to some other good form. If there is a better way to negate statements, I'd like to use it.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.